package team.tunan.mapper;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import team.tunan.entity.Matches;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author sqx
 * @since 2024-01-01
 */
public interface MatchesMapper extends BaseMapper<Matches> {
    // 新增对战
    int addMatch(@Param("playerA") Integer playerA,@Param("aSong") String aSong,@Param("playerB") Integer playerB,@Param("bSong") String bSong,
                 @Param("matchId") Integer matchId,@Param("matchName") String matchName,@Param("roundNum") Integer roundNum,@Param("time") LocalDateTime time);


    @Update("update matches set m_status = #{status}  where mid = #{mid} ")
        // 修改比赛状态 默认为 0 未开始 为 1 进行中 2为 比赛结束
    int updateMatchStatus(@Param("status") Integer status,@Param("mid") Integer mid);

    // 根据 mid 获取对战信息
    @Select("select mid, player_a, a_song, player_b, b_song, m_status, match_id, matchname, roundNum from matches where mid = #{mid}")
    Matches getMatchByMid(@Param("mid") Integer mid);

    // 获取比赛状态
    @Select("select m_status from matches where mid = #{mid}")
    Integer getMatchStatusById(@Param("mid") Integer mid);

    // 获取进行中的比赛
    @Select("select mid, player_a, a_song, player_b, b_song, m_status, match_id, matchname, roundNum from matches where m_status = 1")
    List<Matches> getMatching();

    // 获取比赛状态列表
    @Select("select m_status from matches")
    List<Integer> getMatchStatus();


    //    @Select("SELECT * FROM `matches`")
    List<Map<String,Object>> getMatch(@Param("gid") Integer gid,@Param("roundNum") Integer roundNum);

    @Select("select * from matches where m_status =1 and match_id = #{gid} ")
    List<Map<String, Object>> getNoWinsByGameAndRound(@Param("gid") Integer gid);

    @Select("select mid, player_a, a_song, player_b, b_song, m_status, match_id, matchname, roundNum from matches where m_status =1 ")
    List<Map<String, Object>> getNoWinsByGameAndRound2();

    @Select("select max(roundNum) from matches where match_id = #{gid}")
    Integer MaxRoundNum(@Param("gid") Integer gid);

    List<Map<String, Object>> getMatchs(@Param("gid") Integer gid, @Param("roundNum") Integer roundNum);
}
